<template>
  <div class="outlierAnalysis-container">
    <!--  异常分析  -->
    <div class="analysis-dialog dialogHeaderFont">
      <el-dialog title="异常分析(销售额低于月均销售额)" width="100%" top="8vh"
                 :visible.sync="visible"
                 @close="$emit('update:showdialog', false)">
        <div class="analysis-dialog-content">
          <div class="analysis-content">
            <div class="dialog-content-item" v-for="(item,index) in compareOnLineMarketing" :key="index">
              <div class="dialog-content-delete" v-if="(index > 0)" @click="deleteThisCompare(index)">
                <i class="el-icon-close"></i>
              </div>
              <div class="dialog-content-body">
                <div class="flex-container">
                  <div class="leftSetPadding">
                    终端编号:
                  </div>
                  <div v-text="item.channelId">
                  </div>
                </div>
                <div class="flex-container">
                  <div class="leftSetPadding">
                    所属渠道:
                  </div>
                  <div v-text="item.channelName">
                  </div>
                </div>
                <div class="flex-container">
                  <div class="leftSetPadding">
                    销售量:
                  </div>
                  <div v-text="item.saleCount">
                  </div>
                </div>
                <div class="flex-container">
                  <div class="leftSetPadding">
                    销售额:
                  </div>
                  <div v-text="item.saleAmount">
                  </div>
                </div>
                <div class="flex-container">
                  <div class="leftSetPadding">
                    客流量:
                  </div>
                  <div v-text="item.customerNumber">
                  </div>
                </div>
                <div class="flex-container">
                  <div class="leftSetPadding">
                    进店客数:
                  </div>
                  <div v-text="item.customerNumber">
                  </div>
                </div>
                <div class="flex-container">
                  <div class="leftSetPadding">
                    品类数:
                  </div>
                  <div v-text="item.categoryNumber">
                  </div>
                </div>
                <div class="flex-container">
                  <div class="leftSetPadding">
                    型号数:
                  </div>
                  <div v-text="item.productNumber">
                  </div>
                </div>
                <div class="flex-container">
                  <div class="leftSetPadding">
                    SKU数:
                  </div>
                  <div v-text="item.skuNumber">
                  </div>
                </div>
                <div class="flex-container">
                  <div class="leftSetPadding">
                    平均价格:
                  </div>
                  <div v-text="item.averagePrice">
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="analysis-set">
            <div class="flex-container" @click="analysisSetMonitor" style="cursor: pointer;">
              <div class="" style="font-size: 25px;margin: 0 8px;"><i class="el-icon-plus"></i></div>
              <div class="">添加对比终端</div>
            </div>
          </div>
        </div>
      </el-dialog>
    </div>
    <!--  analysis-dialog容器 -->
    <div class="monitor-dialog-container">
      <!--  添加对比终端  -->
      <el-dialog title="添加对比终端" :visible.sync="monitorDialogVisible"
                 width="60%" top="8vh" append-to-body class="mineSetDialog">
        <div class="outliterSet-dialog-container boederSet paddingSet whiteContainer">
          <div class="outliterSet-dialog-header" style="margin-bottom: 12px;">
            <div class="outliterSet-dialog-searchItem flex-container space-between">
              <div class="mineSearch">
                <el-form :inline="true" :model="onLineChannelControl" class="demo-form-inline single-form-inline mineSetForm" size="mini">
                  <el-form-item label="平台名称" style="margin-bottom: 0px;">
                    <el-input v-model="onLineChannelControl.channelName" placeholder="输入平台名称"></el-input>
                  </el-form-item>
                  <el-form-item style="margin-bottom: 0px;">
                    <el-button type="primary" @click="onSubmitMetaOnLine(onLineChannelControl)">查询</el-button>
                  </el-form-item>
                </el-form>
              </div>
            </div>
          </div>
          <div class="outliterSet-dialog-body">
            <el-table :data="channelMetaSet.channelOnLineSet" stripe
                      border class="setHeight boederSet" style="width: 100%">
              <el-table-column
                prop="channelId"
                width="120"
                label="平台编号">
              </el-table-column>
              <el-table-column
                prop="channelName"
                label="平台名称">
              </el-table-column>
              <el-table-column
                label="选择">
                <template slot-scope="scope">
                  <el-radio v-model="radioUnLineSwitch" @change="radioUnLineChange" :label="scope.row.channelId">添加</el-radio>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="outliterSet-dialog-footer">
            <div class="paginationSet">
              <div class="pagination-container">
                <div class="toStart" @click="handleCurrentChange(1)">首页</div>
                <el-pagination background layout="prev, pager, next"
                               @current-change="handleCurrentChange"
                               :current-page.sync="channelMetaSet.currentPage" :total="channelMetaSet.totalPageOnLine">
                </el-pagination>
              </div>
            </div>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
  import { mapGetters, mapMutations, mapActions } from 'vuex'
  import * as opreate from 'api/getData'

  export default {
    name: "outlier-analysis-on-line",
    props: {
      showdialog: {
        type: Boolean,
        default: false
      }
    },
    computed: {
      ...mapGetters(["compareOnLineMarketing"])
    },
    data() {
      return {
        radioUnLineSwitch: 0,
        visible: this.showdialog,
        channelMetaSet:{
          channelOnLineSet: [], totalPageOnLine: 1, currentPage: 1
        },
        onLineChannelControl: { channelName: '' },
        monitorDialogVisible: false
      }
    },
    mounted() {
      this.onSubmitMetaOnLine()
    },
    methods: {
      ...mapMutations(["updateCompareOnLineMarketing","spliceCompareOnLineMarketing"]),
      handleCurrentChange(pageNumber){
        this.onSubmitMetaOnLine({ pageNumber, ...this.onLineChannelControl })
      },
      radioUnLineChange(channelId){
        opreate.monitorOnLineSearchParams({channelId}).then(res => {
          if(res.data){
            let data = { payload: new Array(res.data) }
            this.updateCompareOnLineMarketing(data)
            this.$message.success('成功查询一条分析数据')
          }else {
            this.$message.error('错了哦，查询信息错误')
          }
        })
      },
      onSubmitMetaOnLine(param){
        opreate.getChannelOnLineControl(param).then(res => {
          let { list, totalRecord, currentPage } = res.data || {}
          this.channelMetaSet = { channelOnLineSet: list || [], totalPageOnLine: totalRecord || 0, currentPage: currentPage || 0 }
        }).catch(err => {
          console.error(err)
        })
      },
      analysisSetMonitor(){
        this.monitorDialogVisible = true
      },
      deleteThisCompare(index){
        this.spliceCompareOnLineMarketing(index)
      }
    },
    watch: {
      showdialog(newVal){
        this.visible = newVal
      }
    }
  }
</script>

<style scoped>
  /**
  * @desc: This is Note
  * 异常分析Dialog
  * @author: WJ
  * @date: 2018/09/26 21:01:27
  **/
  .analysis-dialog-content{
    border: 1px solid #E0E8EF;
    border-radius: 4px;
    display: flex;
    overflow-y: scroll;
    background-color: #ffffff;
  }
  .single-form-inline{
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 40px;
  }
  .plus-item span{
    padding: 0 5px;
  }
  .plus-item .el-icon-plus{
    font-weight: 800;
    font-size: 15px;
  }
  .contrastive-title .borderSet{
    border-right: none;
  }
  .contrastive-body .borderSet{
    border-right: none;
    border-left: none;
  }
  .prod-item:last-child .borderSet {
    border-right: 1px solid #E0E8EF;
  }
  .analysis-content{
    display: flex;
  }
  .dialog-content-item{
    position: relative;
    padding: 12px 30px 12px 12px;
    width: 325px;
    background: white;
    margin-right: 10px;
  }
  .dialog-content-delete{
    position: absolute;
    right: 4px;
    top: -2px;
    font-size: 20px;
    cursor: pointer;
  }
  .dialog-content-item .flex-container{
    height: 30px;
    line-height: 30px;
  }
  .dialog-content-header .flex-container{
    margin-bottom: 6px;
  }
  .dialog-content-body .flex-container{
    padding: 0 12px;
  }
  .leftSetPadding{
    margin-right: 6px;
  }
  .dialog-content-item .dialog-content-body .flex-container:nth-child(odd){
    background: #E0E8EF;
  }
  .dialog-content-item .dialog-content-body .flex-container:nth-child(even){
    background: white;
  }
  .analysis-set{
    width: 200px;
    background: #E0E8EF;
    display: flex;
    justify-content: center;
    min-width: 200px;
  }
</style>
